﻿<UserControl x:Class="MahApps.Metro.Controls.ProgressIndicator"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Controls="clr-namespace:MahApps.Metro.Controls" 
             x:Name="progressIndicator"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>

        <Controls:WidthPercentageConverter x:Key="WidthPercentageConverter" />
        <CircleEase EasingMode="EaseIn" x:Key="ProgressBarEaseIn"/>

        <CircleEase EasingMode="EaseIn" x:Key="ProgressBarEaseOut" />

        <Storyboard RepeatBehavior="Forever" Duration="00:00:04.4" x:Key="animate">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="X" Storyboard.TargetName="R1TT">
                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=0}" />
                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.32}" EasingFunction="{StaticResource ProgressBarEaseOut}" />
                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.65}" />
                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=1}" EasingFunction="{StaticResource ProgressBarEaseIn}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="X" Storyboard.TargetName="R2TT">
                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=0}" />
                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.32}" EasingFunction="{StaticResource ProgressBarEaseOut}" />
                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.65}" />
                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=1}" EasingFunction="{StaticResource ProgressBarEaseIn}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="X" Storyboard.TargetName="R3TT">
                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=0}" />
                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.32}" EasingFunction="{StaticResource ProgressBarEaseOut}" />
                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.65}" />
                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=1}" EasingFunction="{StaticResource ProgressBarEaseIn}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="X" Storyboard.TargetName="R4TT">
                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=0}" />
                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.32}" EasingFunction="{StaticResource ProgressBarEaseOut}" />
                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.65}" />
                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=1}" EasingFunction="{StaticResource ProgressBarEaseIn}" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="X" Storyboard.TargetName="R5TT">
                <LinearDoubleKeyFrame KeyTime="00:00:00.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=0}" />
                <EasingDoubleKeyFrame KeyTime="00:00:00.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.32}" EasingFunction="{StaticResource ProgressBarEaseOut}" />
                <LinearDoubleKeyFrame KeyTime="00:00:02.0" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=.65}" />
                <EasingDoubleKeyFrame KeyTime="00:00:02.5" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},AncestorLevel=1}, Path=ActualWidth, Converter={StaticResource WidthPercentageConverter}, ConverterParameter=1}" EasingFunction="{StaticResource ProgressBarEaseIn}" />
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R1">
                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R2">
                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.4" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R3">
                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.6" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R4">
                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0" />
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00.8" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="R5">
                <DiscreteDoubleKeyFrame KeyTime="0" Value="1" />
                <DiscreteDoubleKeyFrame KeyTime="00:00:02.5" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource animate}"/>
        </EventTrigger>
    </UserControl.Triggers>
    <Border x:Name="IndeterminateRoot" Visibility="Visible"  VerticalAlignment="Stretch">
        <Grid VerticalAlignment="Stretch" Margin="0" HorizontalAlignment="Left">
            <Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="2" x:Name="R1" HorizontalAlignment="Left" >
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="R1TT" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="2" x:Name="R2" HorizontalAlignment="Left" >
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="R2TT" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="2" x:Name="R3" HorizontalAlignment="Left" >
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="R3TT" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="2" x:Name="R4" HorizontalAlignment="Left" >
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="R4TT" />
                </Rectangle.RenderTransform>
            </Rectangle>
            <Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="2" x:Name="R5" HorizontalAlignment="Left" >
                <Rectangle.RenderTransform>
                    <TranslateTransform x:Name="R5TT" />
                </Rectangle.RenderTransform>
            </Rectangle>
        </Grid>
    </Border>
</UserControl>
